//
//  headerView.m
//  waiMai
//
//  Created by LONG on 16/4/14.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "headerView.h"

@interface headerView ()
@property(nonatomic,strong)UIImageView *headerImage;
@property(nonatomic,strong)UILabel *nameLab;
@property(nonatomic,strong)UIImageView *xingImage;
@property(nonatomic,strong)UIImageView *backImage;
@property(nonatomic,strong)UILabel *otherLab;

@end


@implementation headerView
//头像view
- (UIImageView *)headerImage
{
    if(_headerImage ==nil)
    {
        _headerImage =[[UIImageView alloc]init];
        _headerImage.image = [UIImage imageNamed:@"头像"];
        [self addSubview:_headerImage];
    }
    
    return _headerImage;
}
//昵称
- (UILabel *)nameLab
{
    if(_nameLab ==nil)
    {
        _nameLab =[[UILabel alloc]init];
        _nameLab.text = @"我是商家";
        _nameLab.font = [UIFont systemFontOfSize:13];
        [self addSubview:_nameLab];
    }
    
    return _nameLab;
}
//其他
- (UILabel *)otherLab
{
    if(_otherLab ==nil)
    {
        _otherLab =[[UILabel alloc]init];
        _otherLab.text = @"起送价0元 | 配送价 5 元";
        _otherLab.font = [UIFont systemFontOfSize:13];

        [self addSubview:_otherLab];
    }
    
    return _otherLab;
}
//星星view
- (UIImageView *)xingImage
{
    if(_xingImage ==nil)
    {
        _xingImage =[[UIImageView alloc]init];
        _xingImage.image = [UIImage imageNamed:@"星星1"];
        [self addSubview:_xingImage];
    }
    
    return _xingImage;
}
//星星back
- (UIImageView *)backImage
{
    if(_backImage ==nil)
    {
        _backImage =[[UIImageView alloc]init];
        _backImage.image = [UIImage imageNamed:@"星星2"];
        [self addSubview:_backImage];
    }
    
    return _backImage;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    if(self=[super initWithFrame:frame])
    {
        self.backgroundColor=[UIColor whiteColor];
        //self.layer.borderWidth=1;

        [self setview];
    }
    return self;
}
- (void)setview;
{
    
    CGFloat margin = 10;
    
    //设置各控件的frame以及data
    
    //头像
    self.headerImage.sd_layout
    .leftSpaceToView(self,margin)
    .topSpaceToView(self,margin)
    .heightIs(70)
    .widthIs(80);
    
    //昵称
    self.nameLab.sd_layout
    .leftSpaceToView(_headerImage,margin)
    .topSpaceToView(self,1.5 * margin)
    .heightIs(16);
    [_nameLab setSingleLineAutoResizeWithMaxWidth:200];
    
    
    
    //xing
    self.xingImage.sd_layout
    .leftSpaceToView(_headerImage,margin)
    .topSpaceToView(_nameLab,1.5*margin)
    .heightIs(10)
    .widthIs(50);
    //星数
    UIView *bai = [[UIView alloc]init];
    bai.backgroundColor = UIColorFromRGB(0xffffff);
    [self addSubview:bai];
    bai.sd_layout
    .rightEqualToView(_xingImage)
    .topSpaceToView(_nameLab,1.5*margin)
    .heightIs(10)
    .widthIs(15);
    //back
    self.backImage.sd_layout
    .rightEqualToView(_xingImage)
    .topEqualToView(_xingImage)
    .heightIs(10)
    .widthIs(50);
    
    
    //文本
    self.otherLab.sd_layout
    .leftSpaceToView(_headerImage,margin)
    .topSpaceToView(_xingImage,margin)
    .heightIs(16);
    [_otherLab setSingleLineAutoResizeWithMaxWidth:200];
    
    UIView *xian = [[UIView alloc]init];
    xian.backgroundColor = UIColorFromRGB(0xefeff1);
    [self addSubview:xian];
    xian.sd_layout
    .leftSpaceToView(self,2)
    .topSpaceToView(_headerImage,margin)
    .rightSpaceToView(self,2)
    .heightIs(1);
    //
    UIImageView *mapimage =[[UIImageView alloc]init];
    mapimage.image = [UIImage imageNamed:@"icon_location"];
    [self addSubview:mapimage];
    mapimage.sd_layout
    .leftSpaceToView(self,margin)
    .topSpaceToView(xian,5)
    .widthIs(20)
    .heightIs(20);
    
    UILabel *mapLab = [[UILabel alloc]init];
    mapLab.text = @"山东济南历下区华强广场";
    mapLab.font = [UIFont systemFontOfSize:12];
    [self addSubview:mapLab];
    mapLab.sd_layout
    .leftSpaceToView(mapimage,margin)
    .topSpaceToView(xian,8)
    .heightIs(16);
    [mapLab setSingleLineAutoResizeWithMaxWidth:200];
    //
    UIView *xian1 = [[UIView alloc]init];
    xian1.backgroundColor = UIColorFromRGB(0xefeff1);
    [self addSubview:xian1];
    xian1.sd_layout
    .leftSpaceToView(self,2)
    .topSpaceToView(mapimage,5)
    .rightSpaceToView(self,2)
    .heightIs(1);
    //
    UIImageView *timeimage =[[UIImageView alloc]init];
    timeimage.image = [UIImage imageNamed:@"icon_location"];
    [self addSubview:timeimage];
    timeimage.sd_layout
    .leftSpaceToView(self,margin)
    .topSpaceToView(xian1,5)
    .widthIs(20)
    .heightIs(20);
    
    UILabel *timeLab = [[UILabel alloc]init];
    timeLab.text = @"10:00-12:00|12:00-23:59";
    timeLab.font = [UIFont systemFontOfSize:12];
    [self addSubview:timeLab];
    timeLab.sd_layout
    .leftSpaceToView(timeimage,margin)
    .topSpaceToView(xian1,8)
    .heightIs(16);
    [timeLab setSingleLineAutoResizeWithMaxWidth:200];
    //
    UIView *xian2 = [[UIView alloc]init];
    xian2.backgroundColor = UIColorFromRGB(0xefeff1);
    [self addSubview:xian2];
    xian2.sd_layout
    .leftSpaceToView(self,2)
    .topSpaceToView(timeimage,5)
    .rightSpaceToView(self,2)
    .heightIs(1);
}


@end
